"""
任务文件。重置rsakeys
"""
from s_encipher.encipher_rsa import create_key
from user_abt.models import Rsa_Key

from celery_tasks.main import celery_app
# from celery.utils.log import get_task_logger  # 日志
from anytools.logs import log_init
import logging

@celery_app.task()
def reset():
    log_init("celery.log")
    try:
        if Rsa_Key.objects.all():
            # 删除当前数据库中的公私钥
            Rsa_Key.objects.all().first().delete()
        create_key() # 重置公私钥
        logging.info("RSA_RESET  reset success")
    except Exception as ex:
        logging.warning("RSA_RESET  reset fail : {0}".format(ex))
        
